<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;
header('Content-type:text/html;charset=utf-8');

class ReviewController extends AdminbaseController{
    
	public function _initialize() {
		parent::_initialize();
	}
	
	// 后台活动评论列表
	public function reviewlist(){
		$id = I('get.id');
		$type = I('get.type');
		$where=array();
		$where1=array();
		if(!empty($id)){
			$where1["e.reviewid"] = $id;
			$where1["e.type"] = $type;
		}
    	$count = M('Review')
		->table('sp_review e')
		->join("sp_active a on e.reviewid = a.activeid")
		->field("e.*,a.subject")
		->where($where1)
    	->count();
		$size = $page = $this->page($count, 20);
		
		$review=M('Review')
		->table('sp_review e')
		->join("sp_active a on e.reviewid = a.activeid")
		->field("e.*,a.subject")
		->where($where1)
		->order("create_time DESC,id DESC")
		->limit($page->firstRow, $page->listRows)
		->select();
		if(!empty($review) && is_array($review)){
			$existdata=true;
		}else{
			$existdata=false;
		}
		$this->assign("page", $page->show('Admin'));
		$this->assign("review",$review);
		$this->assign("id",$id);
		$this->assign("type",$type);
		$this->assign("existdata", $existdata);
		$this->display();
	}
	
	// 活动评论编辑
	public function reviewedit(){
		$id=I("get.id",0,'intval');
		$aid=I("get.aid",0,'intval');
		$type=I("get.type",0,'intval');
		$review=M('Review')
		->where(array("id"=>$id))
		->find();
		$this->assign('review',$review);
		$this->assign('aid',$aid);
		$this->assign('type',$type);
		$this->display();
	}
	
	// 活动评论编辑提交
	public function reviewedit_post(){
		if (IS_POST) {
			$id = I('post.id');
			$aid = I('post.aid');
			$type = I('post.type');
    		$data = I("post.frm");
			if (M('Review')->where(array("id"=>$id))->save($data)!==false) {
				$this->success("编辑成功",U("Review/reviewlist",array('id'=>$aid,'type'=>$type)));
			} else {
				$this->error("编辑失败！");
			}
		}
	}
	
	// 活动评论删除
	public function reviewdel(){
		$id = I("get.id",0,"intval");
		if (M('Review')->where(array("id"=>$id))->delete()!==false) {
			$this->success("删除成功！");
		} else {
			$this->error("删除失败！");
		}
	}
}